package edu.utd.text.game.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * GameObject
 * Game objects are objects in the game that are not players
 * or areas/rooms that a user may be able to interact with.
 * By subclassing, these objects may include carry-able objects
 * or interactive objects, or inert objects in the game.
 * 
 * A GameObject also has tags, which help a player
 * identify it when trying to interact with it.  Each subclass of
 * abstract GameObject can only have one true *type*, but may
 * be associated with multiple tags, so the player
 * may be able to refer to it by any one of those tags
 * which the game controller can then interpret
 * to figure out what the user is talking about.
 * 
 * @author troy
 *
 */

abstract public class GameObject implements Descriptive, Serializable {
	
	private ArrayList<String> tags = new ArrayList<String>();
	protected String name;
	protected String description;
	
	  //////////
	 // Tags //
	//////////
	
	//TODO : Test this
	public void addTag(String aTag) {
		//don't add duplicates
		for (String s : tags) {
			if(s.equals(aTag)) return;
		}
		tags.add(aTag);
	}
	
	//TODO : Test this method!
	public void addTags(String... newTags){
		Arrays.asList(newTags);
		for (String newTag : newTags) { 
			addTag(newTag);	
		}
	}
	
	public boolean tagsMatch(String searchTag) {
		for (String tag : getTags()) {
			if(tag.trim().equalsIgnoreCase(searchTag.trim())) { 
				return true;
			}
		}
		return false;
	}

	
	  /////////////
	 // Getters //
	/////////////
	
	public String getName() {
		return name;
	}
	
	public ArrayList<String> getTags() { return this.tags; }
	

	  /////////////
	 // Setters //
	/////////////
	
	public void setName(String name) {
		this.name = name;
	}
	
	public void setTags(ArrayList<String> tags) { this.tags = tags; }
	
	
	public void setDescription(String description) {
		this.description = description;
	}
	
	  ///////////////////
	 // Equals method //
	///////////////////
	
	public boolean equals(Object other) {
		if (other instanceof GameObject) {
			return this.getName().equals(((GameObject)other).getName());
		}
		return false;
	}

}
